<!--
    选择业务员跟进的客户
-->
<template>
    <div class="bg-content">
        <div style="background-color: white;">
            <u-search placeholder="请输入搜索关键词" shape="square" v-model="searchKeyword" @search="onSearch" @custom="onSearch"></u-search>
            <u-cell-group>
                <u-cell-item v-for="(item, index) of tbCommunityUserList" :key="item.id" :title="'(' + item.code + ') ' + item.name" :arrow="true"
                             @click="select(item)"></u-cell-item>
            </u-cell-group>
        </div>
        <div style="padding-top: 10px; padding-bottom: 10px;">
            <u-loadmore :status="pagination.status" bg-color="#eeeeee"/>
        </div>
    </div>
</template>

<script>
    import {CommonUtil} from "../../../dev/core/utils/common.util";
    import {SysUserService} from "../../../dev/services/sys-user.service";
    import {LocalStorageUtil} from "../../../dev/core/utils/local-storage.util";
    import {TbCommunityUserService} from "../../../dev/services/tb-community-user.service";

    export default {
        data: function () {
            return {
                returnPageUrl: '/pages/sub/sub1-tabs/tabs/index',
                searchKeyword: '',
                tbCommunityUserList: [],
            }
        },
        onShow() {
            // 自定义返回页面
            if (this.urlParams.returnPageUrl) {
                this.returnPageUrl = this.urlParams.returnPageUrl;
            }
            this.doRefresh(this.tbCommunityUserList);
        },
        methods: {
            onSearch(event) {
                this.searchKeyword = CommonUtil.trim(this.searchKeyword);
                this.doRefresh(this.tbCommunityUserList);
            },
            select(item) {
                const _self = this;
                new SysUserService().markTbCommunityUserTypeById(item.communityUserTypeId).then(result => {
                    _self.globalVariable.userInfo = result.userInfo;
                    _self.globalVariable.userInfo.customerName = item.name;
                    LocalStorageUtil.setItem("userInfo", _self.globalVariable.userInfo);
                    uni.reLaunch({
                        url: _self.returnPageUrl
                    });
                });
            },
            /**
             * 加载更多数据中
             * @param infiniteScroll
             */
            doInfinite(infiniteScroll) {
                const _self = this;
                new TbCommunityUserService().findTableTbCommunityUserListBySalesman({
                    pagination: _self.pagination,
                    data: {
                        communityId: _self.globalVariable.userInfo.tbCommunity.id,
                        communityUserIds: _self.globalVariable.userInfo.tbCommunityUser.id,  // 客户跟进人员
                        searchKeyword: _self.searchKeyword,
                        status: '1',
                        deleted: 0
                    }
                }).then(result => {
                    _self.pagination.refreshPage(result);
                    _self.tbCommunityUserList = [..._self.tbCommunityUserList, ...result.list];
                });
            }
        },
        // watch: {
        //     isShow: {
        //         deep: true, // 深度监听
        //         handler(newVal, oldVal) {
        //             console.log(newVal, oldVal);
        //             if (newVal) {
        //                 CommonUtil.doRefresh(this, this.tbCommunityUserList, null);
        //             }
        //         }
        //     }
        // },
    }
</script>

<style>
    .page-login-community-user-type-select {

    }

    /*.page-login-community-user-type-select-wrapper {*/
    /*!*display: flex;*!*/
    /*!*align-items: center;*!*/
    /*!*justify-content: center;*!*/
    /*height: 100%;*/
    /*background: #eeeeee;*/
    /*}*/
</style>
